<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 避免IE使用兼容模式 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="renderer" content="webkit" />
<title>主页</title>

    <link rel="stylesheet" type="text/css" href="../../plugins/bootstrap/3.3.7/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../../plugins/jquery-easyui/1.8.6/themes/gray/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../plugins/jquery-easyui/1.8.6/themes/icon.css" />
    <!-- font-awesome图标字体 -->
    <link rel="stylesheet"  href="../../plugins/font-awesome/css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="../../plugins/toastr/2.1.4/toastr.min.css" />
    
    <link rel="stylesheet" type="text/css" href="../../plugins/select2/4.0.13/css/select2.min.css" />
    
    <link rel="stylesheet" type="text/css" href="../../plugins/codemirror/lib/codemirror.css" />
    <link rel="stylesheet" type="text/css" href="../../plugins/codemirror/addon/display/fullscreen.css" />
    <link rel="stylesheet" type="text/css" href="../../plugins/codemirror/theme/dracula.css" />
    <link rel="stylesheet" type="text/css" href="../../plugins/codemirror/addon/hint/show-hint.css" />
    
    
    <link rel="stylesheet" href="../../plugins/zTree_v3/css/zTreeStyle/zTreeStyle.css" media="all" />

    <link rel="stylesheet" type="text/css" href="../../css/zbootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../../css/zeasyui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/common.css" /> 
    
    <script type="text/javascript" src="../../plugins/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="../../plugins/jquery-rstorage/1.3.2/jquery.rStorage.min.js"></script>
    <script type="text/javascript" src="../../plugins/jquery-easyui/1.8.6/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="../../plugins/clipboard/2.0.6/clipboard.min.js"></script>
    <script type="text/javascript" src="../../plugins/toastr/2.1.4/toastr.min.js"></script>
    
    <script type="text/javascript" src="../../plugins/zTree_v3/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="../../plugins/zTree_v3/js/jquery.ztree.exhide.js"></script>
    <script type="text/javascript" src="../../plugins/zTree_v3/js/fuzzysearch.js"></script>
    
    <script type="text/javascript" src="../../plugins/codemirror/lib/codemirror.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/mode/clike/clike.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/mode/xml/xml.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/mode/css/css.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/mode/javascript/javascript.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/mode/htmlmixed/htmlmixed.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/mode/sql/sql.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/hint/xml-hint.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/hint/show-hint.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/hint/sql-hint.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/hint/html-hint.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/hint/css-hint.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/hint/javascript-hint.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/selection/selection-pointer.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/display/autorefresh.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/display/placeholder.js"></script>
    <script type="text/javascript" src="../../plugins/codemirror/addon/edit/matchbrackets.js"></script>
    
    
    <script type="text/javascript" src="../../js/zGlobal.js"></script>
    <script type="text/javascript" src="../../js/zApi.js"></script>
    <script type="text/javascript" src="../../js/zUtil.js"></script>
    <script type="text/javascript" src="../../js/zAlert.js"></script>
    <script type="text/javascript" src="../../js/zDict.js"></script>
    <script type="text/javascript" src="../../js/zTable.js"></script>
    <script type="text/javascript" src="../../js/zDialog.js"></script>
    <script type="text/javascript" src="../../js/zForm.js"></script>
    <script type="text/javascript" src="../../js/zJson.js"></script>
    
    <![if IE]>

    <![endif]>

</head>
<style>
#dlg-detail textarea{
    line-height: 25px;
}
.datagrid-header-row > td > div{
    line-height: 35px;
}
.tabs-header .tabs-inner{
   overflow: hidden;
   text-overflow: ellipsis;
   -o-text-overflow:ellipsis;
   max-width: 200px;
}
.tabs-header{
     -moz-user-select: none;  
     -webkit-user-select: none;
     -ms-user-select: none;
     -khtml-user-select: none;
     -webkit-touch-callout: none;
     user-select: none;
}
.menu-shadow{
-moz-box-shadow: unset;
-webkit-box-shadow: unset;
box-shadow: unset;
}
.ztree-btn-group{
    float: right;
    position: absolute;
    right: 0;
    top: 0;
    line-height: 12px;
}
.ztree-opr-btn{
    line-height: 13px;
    margin-left: 5px;
    margin-right: 5px;
    padding: 0;
    display: inline;
}
.ztree li {
    position: relative;
}
</style>
<body onload="noright(document.body);">
  <div class="easyui-layout" data-options="fit:true"> 
   <div class="main-content">
     <div class="easyui-layout" data-options="fit:true,border:false">
       <div class="no-tip"data-options="region:'west',split:true,border:false,title:'表',expandMode:'dock',minWidth:200,maxWidth:600" style="overflow: hidden;width:30%;border-right:1px solid rgb(210, 208, 208);"> 
          <div class="easyui-layout" data-options="fit:true,border:false">
         <div class="no-tip"data-options="region:'north',split:false,border:false,title:''" style="overflow: hidden;height:50px;width:auto;border-right:1px solid rgb(210, 208, 208);"> 
          <div class="row" style="margin-top: 10px;">
            <div class="col-sm-7">
             <input  id="querystr" name="querystr" class="form-control" style="width:100%;" />
             </div>
             <div class="col-sm-5">
             <select id="projectId" name="projectId"  class="form-control" style="width:100%;" ></select>
             </div>
                 <button  id="t-copy" data-clipboard-target="#stext"  style="display: none;"></button>
                 <input id="stext" name="stext" style="position: absolute;left: 0;z-index: -1;" />
           </div>
         </div>
         <div class="no-tip" data-options="region:'center',split:false,border:false,title:''" style="overflow: hidden;width:auto;border-left:1px solid rgb(210, 208, 208);"> 
          <div style="height:100%;position: relative;border: 1px solid #D2D2D2;">
           <div class="overflow-y"><ul id="tree-code-file" class="ztree"></ul></div>
          </div>
          </div>
         </div>
       </div>
       <div class="no-tip" data-options="region:'center',border:false,title:'SQL编辑器',minWidth:400" style="overflow: hidden;height:100%;width:auto;border-left:1px solid rgb(210, 208, 208);"> 
          <div style="width:100%;height:100%;position: relative;border: 1px solid #D2D2D2;">
          <div id="tabs" style="">
          </div>
          <div id="tab-tools">
              <button href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fa fa-plus fa-1'" title="新增一个" onclick="tabPanelAdd(null,true)"></button>
              <button href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fa fa-close fa-1'" title="关闭最后一个" onclick="tabPanelRemove('1')"></button>
              <button href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fa fa-window-close fa-1'" title="全部关闭" onclick="tabPanelRemove('2')"></button>
          </div>
          </div>
       </div>
      </div>
   </div> 
  </div>

  
  <div id="dlg-detail" style="display:none;">
   <div class="main-content">
    <form>
     <div class="row">&nbsp;</div> 
     <div class="row padding-right" id="rowdiv">
     </div> 
     <div class="row"> &nbsp;</div>
     <div class="row">&nbsp;</div> 
    </form>
   </div>
  </div>
  

 <script>
 var CJSON ={};
 var CanUseTableDATA = {};
 var AllTableKeys ={};
 var zNodes = [];
 var cSelected = null;
 var menuObj = null;
 var CITEM = {};
 $(function(){
     zUtil.dictLoadSyncOfAutocode("ZSELECT_PROJECT");
     if(!zDictAutocode['ZSELECT_PROJECT'] || zDictAutocode['ZSELECT_PROJECT'].length==0){
         zUtil.msg("未配置项目信息");
         return;
     }
     $.each(zDictAutocode['ZSELECT_PROJECT'],function(k,item){
           $('#projectId').append('<option value="'+k+'">'+item['labelCode']+'</option>');
           CITEM[item['projectId']] = item['labelCode'];
     });
     $('#projectId').on('change',function(){
         $.fn.zTree.getZTreeObj("tree-code-file").destroy();
         setTableDataTree();
         
         getTableCodeEditor().setOption("hintOptions", 
                 {
                  completeSingle: false,  //关闭补全
                  tables: $.extend(true,{},AllTableKeys)
                }
         );
     });
     
     setTableDataTree();
     fuzzySearch('tree-code-file','#querystr',null,false); //初始化模糊搜索方法
     zUtil.clip('#t-copy',{
       success:function(e) {
//           zUtil.Toastr("success","已复制");
       }
     });
     
     $('#tabs').tabs({
         tools : '#tab-tools',
         fit : true,
         border : false,
         iframe: true,
         top : 0,
         onSelect : function(title, index) {
             cSelected = $('#tabs').tabs('getTab',index).attr('id');
             var titles = $('#tabs .tabs-header .tabs>li').eq(index).find(".tabs-inner>span").html();
             var spval =  $('#projectId').val();
             spval = CITEM[$('#projectId').val()] && index!==0?CITEM[$('#projectId').val()]+"--":"";
             $('#tabs .tabs-header .tabs>li').eq(index).find('.tabs-inner').attr("title",spval+titles);
         },
         onContextMenu : function(e, title,index){
             var alltabs = $('#tabs').find('.tabs>li');
             
             e.preventDefault();
             if (menuObj){
                 menuObj.menu('destroy');
             }
             var showcss = 'glyphicon glyphicon-ok text-primary';
             var hidecss = 'glyphicon glyphicon-remove text-muted';
             menuObj = $('<div id="tabs-right-menus"/>').appendTo('body');
             menuObj.menu({
//               hideOnUnhover: false,
                 onClick: function(item){
                     menuObj.find('.menu-item .menu-icon').removeClass(showcss);
                     menuObj.find('.menu-item .menu-icon').addClass(hidecss);
                     $('#tabs').tabs('select',item.tabid);
                     menuObj.menu('setIcon', {
                         target: item.target,
                         iconCls: showcss,
                     });
                     menuObj.menu('show');
                 }
             });
             var sidx = $('#tabs').tabs('getTabIndex',$('#tabs').tabs('getSelected'));
             $.each(alltabs,function(i,item){
                 var title = $(item).find(".tabs-inner").attr('title');
                 menuObj.menu('appendItem', {
                     text: title,
                     tabid: i,
                     iconCls: sidx===i?showcss:hidecss
                 });
             });
             menuObj.menu('show', {
                 left:e.pageX,
                 top:e.pageY
             });
         }
     });
     tabPanelAdd();
 });
 function setTableDataTree(){
      CanUseTableDATA = {};
      AllTableKeys ={};
      zNodes = [];
      var tblcols = zUtil.ajaxGetSync(zGlobal["http"] + "/api/autocode/table/columnlist", { projectId: $('#projectId').val()});
        var resdata = tblcols[zConst["resData"]][zConst["data"]];
        if(resdata){
            for(var i=0; i< resdata.length; i++){
                var  d = resdata[i];
                var tcol =[];
                var allcols = d["columnInfos"];
                 if(allcols && allcols.length>0){
                    $.each(allcols,function(i,item){
                        tcol.push({
                            "columnCode": item['columnCode'],
                            "columnJavaCode": item['columnJavaCode']
                        });
                        var cid = zUtil.uuid();
                        var cNode = {
                                id: cid
                               ,pId: d['tableCode']
                               ,name: item['columnCode']+"___【"+item['columnTitle']+"】___"+d['tableCode']
                               ,chkDisabled: true
                               ,nocheck: true
                               ,isParent: false
                               ,tabledata:{"code":item['columnCode']
                                          ,"title":item['columnTitle']
                                          ,"projectId": $('#projectId').val()
                                          , "oprType": "2"
                                }
                               ,font:{'color':'#000'}
                        };
                        zNodes.push(cNode);
                    });
                } 
                CanUseTableDATA[d['tableCode']] = tcol;
                AllTableKeys[d['tableCode']] = [];
                
                var fNode = {
                        id: d['tableCode']
                       ,pId: "0"
                       ,name: d['tableCode']+"----"+d['tableTitle']
                       ,chkDisabled: true
                       ,nocheck: true
                       ,isParent: true
                       ,open: false
                       ,tabledata:{  "code": d['tableCode']
                                  ,  "title": d['tableTitle']
                                  ,"projectId": $('#projectId').val()
                                  , "oprType": "1"
                       }
                       ,font:{'color':'blue'}
                };
                zNodes.push(fNode);
            }
        }
        
        var setting = {
                check: {
                    enable: true
                   ,chkDisabledInherit: false
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                view: {
                    nameIsHTML: true
                    ,fontCss: function(treeId, node) {
                        return node.font ? node.font : {};
                    },
                    addDiyDom: function(treeId, treeNode) {
                        var tdata = treeNode['tabledata'];
                        var oprType = tdata['oprType'];
                        var projectId = tdata['projectId'];
                        var tablecode = tdata['code'];
                        var diyObj = $('<div class="ztree-btn-group"><button class="btn btn-info ztree-opr-btn" onclick="doQueryTableData(\''+treeNode.tId+'\',\''+projectId+'\',\''+tablecode+'\');">查询</button></div>');
                        if(oprType==="1"){
                            $('#'+treeNode.tId+'_a').append(diyObj);
                        }
                    },
//                     showIcon: false
                },
                callback: {
                     onClick : function(event, treeId, treeNode){
                          $('#stext').val(treeNode['tabledata']['code']);
                          $('#t-copy').click();
                     },
                     /* onDblClick : function(event, treeId, treeNode){
                         var oprType = treeNode['tabledata']['oprType'];
                         if(oprType==="1"){
                             tabPanelAdd(treeNode['tabledata'],true);  
                         }else if(oprType==="2"){

                         }
                    }, */
                }
       };
       
       //树形结构初始化
       codeFileTree  =  $.fn.zTree.init($("#tree-code-file"), setting, zNodes);
       
 }
 function doQueryTableData(tId,databaseId,tablecode){
     var treeNode = $.fn.zTree.getZTreeObj("tree-code-file").getNodeByTId(tId);
     tabPanelAdd(treeNode['tabledata'],true);
 }
 function getTableCodeEditor(){
     var editorObj = $('#'+cSelected + ' #tableData').next('.CodeMirror')[0].CodeMirror;
     return editorObj;
 }
  function configForTableCodeEditor(){
        var editorObj = $('#'+cSelected + ' #tableData').next('.CodeMirror');
        var TableCodeEditor = null;
        if(editorObj.length === 0){
            TableCodeEditor = CodeMirror.fromTextArea($('#'+cSelected + ' #tableData')[0], {
                  autoRefresh:true,
                  lineNumbers: true,
                  styleActiveLine: true,
                  matchBrackets: true,
                  lineWrapping: true,
//                  indentWithTabs: true,
//                  smartIndent: true,
//                  autofocus: false,
//                  tabSize: 4,
                  mode:"text/x-hive",
                  theme: 'dracula',
                  extraKeys: { // 触发按键
                  },
                  hintOptions: {
                      completeSingle: false,  //关闭补全
                      tables: AllTableKeys
                  }
             });
            TableCodeEditor.setSize('100%','100%');
            
            TableCodeEditor.on("change",function(){
                configForTableSqlEditItem();
            });
            TableCodeEditor.on('keypress', () => {
                //编译器内容更改事件
                TableCodeEditor.showHint();
            });
        }else{
            TableCodeEditor = editorObj[0].CodeMirror;
        }
        TableCodeEditor.setValue('');
        TableCodeEditor.setOption("hintOptions", {
            completeSingle: false,  //关闭补全
            tables: AllTableKeys
        });
 }
  function configForTableSqlEditItem(){
        var tTableKeys = "";
        var i=0;
        $.each(CanUseTableDATA,function(key,val){
            tTableKeys += i==0?key:"|"+key;
            i++;
        });
        if(tTableKeys && tTableKeys.trim().length>0){
            var ntblstr = getTableCodeEditor().getValue();
            if(ntblstr&& ntblstr.trim().length>0){
                ntblstr = ntblstr.replace(new RegExp('\\n','g')," ").replace(new RegExp(' +','g'),' ');
                
                var regs =new RegExp("\\b("+tTableKeys+") +[A-Za-z]+[0-9]*","g");
                var farr = ntblstr.match(regs);
                if(farr && farr.length>0){
                   var needTbls = {};
//                    console.log(farr);
                   $.each(farr,function(i,item){
                     var tkeys = item.split(' ');
                     var htbl = CanUseTableDATA[tkeys[0]];
                     if(htbl){
                         var fieldArr =[];
                         $.each(htbl,function(i,fv){
                             needTbls[fv['columnJavaCode']] = [];
                             needTbls[tkeys[1]+"."+fv['columnCode']] = [];
                         });
                     }
                   });
                   var  ohopts = getTableCodeEditor().getOption("hintOptions");
                   setTimeout(function(){
                       getTableCodeEditor().setOption("hintOptions", 
                           {
                            completeSingle: false,  //关闭补全
                            tables: $.extend(true,{},AllTableKeys, needTbls)
                          }
                       );
                   }, 400);
                }
            }
        }
    }
  
  //初始化表格
  function tableLoad(data,columns,pageNumber,pageSize){
        var buttonsIdxRight = [4];
        var buttonsFuncRight = [sqlQuery];
        var optionsRight = {
                queryParams:{},
                data : [],
                idField: null,
                columns:[[
                ]],
                frozenColumns:[[
                   {field:'buttonArr', title:'操作', align:'center', width: 60, formatter: function(value,rowData,rowIndex){
                        return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="dlgDetail('+rowIndex+');" title="详情" ><i class="fa fa-eye"> </i></a> ';
                        }
                   },
                ]],
                onDblClickCell: function(rowIndex, field, value){
                    if("buttonArr" != field){
                    
                    }
                },
                onSelect: function(rowIndex, rowData){
                },
                onHeaderContextMenu: function(e, field){
                    CJSON['TableHeaderRightMenu'+cSelected] = zUtil.tableHeaderMenu(e,CJSON['TableHeaderRightMenu'+cSelected],'#'+cSelected + ' #table-sql-result');
                },
        };
        if(columns){
            optionsRight['columns'] = [columns];
        }
        if(data){
            optionsRight['data'] = data;
        }
        if(pageNumber){
            optionsRight['pageNumber'] = pageNumber;
        }
        if(pageSize){
            optionsRight['pageSize'] = pageSize;
        }
        zUtil.tableInit('#'+cSelected + ' #table-sql-result',optionsRight,buttonsIdxRight,buttonsFuncRight);
        zUtil.tablePage('#'+cSelected + ' #table-sql-result').pagination({
            onSelectPage: function(pageNumber, pageSize){
               sqlQuery();
            },
            onRefresh: function(pageNumber, pageSize){
              sqlQuery();
            },
            onChangePageSize: function(pageSize){
              sqlQuery();
            }
       });
  }
  function sqlQuery(){
      CJSON['TableHeaderRightMenu'+cSelected] = null;
      var sqlstr = getTableCodeEditor().getValue();
      var tpageOpts = zUtil.tablePage('#'+cSelected + ' #table-sql-result').pagination('options');
      var pageNumber=tpageOpts.pageNumber>0?tpageOpts.pageNumber:1;
      var pageSize=tpageOpts.pageSize>0?tpageOpts.pageSize:20;
      
      if(!sqlstr || sqlstr.length<20){
          zUtil.Toastr("error","请输入查询sql");
          return false;
      }
       
      
      var reqData = {reqData: {
                               sqlStr: sqlstr,
                               projectId: $('#projectId').val(),
                               page: pageNumber,
                               limit: pageSize,
                              }
                     };
      var result = zUtil.ajaxPostSync(zGlobal["http"] + "/api/online/disql/list", reqData);
      if(zCode["GLOBAL_SUCCESS"] == zUtil.getVal(result,zConst["busCode"])){
          result = result[zConst["resData"]];
          var list = result.list;
          var total = result.total;
          if(!list || list.length == 0 || total ==0){
              zUtil.Toastr("warn","无查询结果或条件错误");
          }
          var columns =[];
          var fields = result.fields;
          if(fields && fields.length>0){
              $.each(fields,function(i,item){
                 var col = {field: item, title: item, align: 'center', width: 150
                         ,formatter: function(value,rowData,rowIndex){
                             if(value && value.length>100){
                                 return value.substr(0,50)+"......省略了看详情";
                             }
                             return value;
                         }
                 };
                 columns.push(col);
              });
          }else{
              columns.push({field: 'fieldDefault', title: '默认', align: 'center', width: 100})
          }
          columns.push({field: ' ', title: ' ', align: 'center', width: 100});
          tableLoad({rows: list, total: total},columns,pageNumber,pageSize);
      }else{
          var emsg = result[zConst["busMsg"]];
          if(emsg && emsg.length>610){
             emsg = emsg.substr(0,600);
          }
          zUtil.Toastr("error","查询失败，请检查 "+ emsg);
          return false;
      }
  }
  function dlgDetail(row){
      $('#dlg-detail').find('#rowdiv').empty();
      zUtil.tableSelected('#'+cSelected + ' #table-sql-result',row);
      row = zUtil.tableRows('#'+cSelected + ' #table-sql-result');
      
      $.each(row,function(k,v){
          var hobj = $('<div class="col-sm-6"> <label class="form-lable5">'+k+'</label>'
                     +'<div class="input-block5"><input class="easyui-textbox" id="'+k+'"  name="'+k+'" data-options="multiline:true" style="width:100%;height:30px;" /> </div>' 
                     +'</div>');
                  $('#dlg-detail').find('#rowdiv').append(hobj);
                  zUtil.inputInit("#dlg-detail #"+k, 'input');
      });
      
        var dlgClose = function(){
          zUtil.dialogClose('#dlg-detail');
        };
        var dlgOptions = {
          title: '详情',
          onOpen:function(){
              zUtil.areaSize('#dlg-detail',{minHeight: 30});
          }
        };
        var dlgButtonsIdx = [1];
        var dlgButtonsFunc =  [dlgClose];
        zUtil.dialogInit('#dlg-detail',dlgOptions,dlgButtonsIdx,dlgButtonsFunc);
        zUtil.valAll('#dlg-detail',row);
        zUtil.dialogOpen('#dlg-detail');
  }
  
  
  //增加TAB页
  function tabPanelAdd(data,closeable){
      var id = zUtil.uuid();
      var dselect = null;
      if(data){
         dselect = 'SELECT * FROM ' + data['code'] +" t";
      }
      var title = data?data['code']:"默认";
      $('#tabs').tabs('add',{
          title: title,
          href: './onlineSqlQuery.html',
          id: id,
          closable: closeable?true:false,
          border: true,
          iconCls: 'fa fa-th',
      });
      
      setTimeout(function(){
          configForTableCodeEditor();
          
          if(dselect!=null){
             getTableCodeEditor().setValue(dselect);
          }
          
          tableLoad();
          if(dselect!=null){
              sqlQuery();
          }
      },200);
  };
  //移除TAB页
  function tabPanelRemove(type){
      var tabs = $('#tabs').tabs('tabs');
      if (tabs && tabs.length>=2){
         if(type==="1"){
             delete CJSON['TableHeaderRightMenu'+ tabs[tabs.length-1].attr('id')];
             var index = $('#tabs').tabs('getTabIndex', tabs[tabs.length-1]);
             $('#tabs').tabs('close', index);
         }else if(type==="2"){
             for(var i=tabs.length-1; i>=1; i--){
                 delete CJSON['TableHeaderRightMenu'+ tabs[i].attr('id')];
                 var index = $('#tabs').tabs('getTabIndex', tabs[i]);
                 $('#tabs').tabs('close', index);
             }
         }
      }
      
      
  };
  
  </script>
</body>
</html>